@extends('admin.common.base-master')

@section('html-head')
    <link href="{{url('css/jquery.form.css')}}" type="text/css" rel="stylesheet" />
    <script src="{{url('/js/lib/jquery.form.js')}}"></script>
    <style>
        .btn_add_classify{
            background: #31bcd3;margin-left:10px;height: 5px;width: 50px;color: white;text-align: center;padding:5px;border-radius:7px;box-shadow: 3px 2px 9px #888888;
        }
    </style>
@endsection

@section('html-body')
    <div id="content">
        <div id="cur-position">
            <span class="tit">当前位置：</span>
            <a href="{{route('Admin.Home.joyInfoList')}}">开心娱乐</a>
        </div>

        <div class="filter-box clearfix">

            <div class="fr">
                <a class="addBtn" href="{{route("Admin.Home.joySet")}}">新增</a>
            </div>
        </div>
        <div class="table-box">
            <table class="table">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>图片</th>
                    <th>标题</th>
                    <th>链接</th>
                    <th>描述</th>
                    <th>创建时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @if(count($joys) > 0)
                    @foreach($joys as $joy)
                        <tr id="joy_{{$joy->id}}">
                            <td>{{$joy->id}}</td>
                            <td class="account-td" style="width: 5%;">
                                <span class="photo" style="border-radius: 100%;display:initial">
                                    @if($joy->img_id !== 0)
                                        <a href="javascript:void(0);" class="openimg" data-key="{{$joy->img_id}}"><img src="{{$joy->photo_url}}" alt="{{$joy->photo_url}}"></a>
                                    @else
                                        <img src="{{url('images/default-img.png')}}" alt="">
                                    @endif
                                </span>
                            </td>
                            <td>{{$joy->title}}</td>
                            <td><a href="{{$joy->link_url}}" >{{$joy->link_url}}</a></td>
                            <td>{{$joy->desc}}</td>
                            <td>{{$joy->created_at}}</td>
                            <td><a class="color2" href="{{route("Admin.Home.joySet")}}?id={{$joy->id}}">编辑</a> <span>|</span> <a href="javascript:void(0);" class="del" data-id="{{$joy->id}}">删除 </a></td>
                        </tr>
                    @endforeach
                @endif
                </tbody>
            </table>
            <?php echo $joys->render();?>
        </div>
    </div>
    <script>
        $(document).on("click",".del",function(){
            var id = $(this).attr("data-id");

            noty({
                text: '你确定要删除吗?',
                buttons: [
                    {addClass: 'btn btn-primary', text: '确定', onClick: function($noty) {
                            $noty.close();
                            $.ajax({
                                url:'{{route('Api.Admin.sys.delJoy')}}',
                                type:'post',
                                dataType:'json',
                                data:{id:id},
                                success:function(obj){
                                    if(obj.level == "success"){
                                        $("#joy_"+id).hide('slow');
                                    }else{
                                        noty({type:obj.level,text:obj.message,timeout:600});
                                    }
                                },
                                error:function(obj){
                                    console.log(obj);
                                }

                            });
                        }
                    },
                    {addClass: 'btn btn-danger', text: '取消', onClick: function($noty) {
                            $noty.close();
                        }
                    }
                ]
            });

        });


    </script>
@endsection
